package cn.hnbjx.prepaid.utils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

public class StringUtils extends org.apache.commons.lang3.StringUtils{
    /**
     * StringUtils工具类方法
     * 获取一定长度的随机字符串，范围0-9，a-z
     * @param length：指定字符串长度
     * @return 一定长度的随机字符串
     */
    public static String getRandomStringByLength(int length) {
        String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }
    /**
     * StringUtils工具类方法
     * 获取一定长度的随机字符串，范围0-9，a-z
     * @param length：指定字符串长度
     * @return 一定长度的随机字符串
     */
    public static String getRandomByLength(int length) {
        String base = "123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }

    /**
     * StringUtils工具类方法
     * 获取一定长度的随机字符串，范围0-9，a-z
     * @param length：指定字符串长度
     * @return 一定长度的随机字符串
     */
    public static String getRandom(int length) {
        String base = "12";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }

    public static List ticket1() {
        int price = new Random().nextInt(1001)+2500;
        System.out.println(price);
        double a=0;
        double b=0;
        double c=0;
        double d=0;
        int num=0;
        String[] x=new String[4];
        for (int i=0;i<4;i++){
            if (i==0){
                price=price-num;
                num= new Random().nextInt(price+1);
                a=num*0.01;
                BigDecimal a1= new BigDecimal(a);
                String a2= String.valueOf(a1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                x[0]=a2;
            }
            if (i==1){
                price=price-num;
                num= new Random().nextInt(price+1);
                b=num*0.01;
                BigDecimal b1= new BigDecimal(b);
                String b2= String.valueOf(b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                x[1]=b2;
            }
            if (i==2){
                price=price-num;
                num= new Random().nextInt(price+1);
                c=num*0.01;
                BigDecimal c1= new BigDecimal(c);
                String c2= String.valueOf(c1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                x[2]=c2;
            }
            if (i==3){
                num= new Random().nextInt(price+1);
                d=num*0.01;
                BigDecimal d1= new BigDecimal(d);
                String d2= String.valueOf(d1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                x[3]=d2;
            }
        }
        List list = new ArrayList();
        for(int i = 0;i < x.length;i++){
            System.out.print(x[i]+", ");
            list.add(x[i]);
        }
        Collections.shuffle(list);
        return list;
    }

    public static List ticket2() {
        int price = new Random().nextInt(601)+900;
        System.out.println(price);
        double a=0;
        double b=0;
        double c=0;
        double d=0;
        int num=0;
        String[] x=new String[4];
        for (int i=0;i<4;i++){
            if (i==0){
                price=price-num;
                num= new Random().nextInt(price+1);
                a=num*0.01;
                BigDecimal a1= new BigDecimal(a);
                String a2= String.valueOf(a1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                x[0]=a2;
            }
            if (i==1){
                price=price-num;
                num= new Random().nextInt(price+1);
                b=num*0.01;
                BigDecimal b1= new BigDecimal(b);
                String b2= String.valueOf(b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                x[1]=b2;
            }
            if (i==2){
                price=price-num;
                num= new Random().nextInt(price+1);
                c=num*0.01;
                BigDecimal c1= new BigDecimal(c);
                String c2= String.valueOf(c1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                x[2]=c2;
            }
            if (i==3){
                num= new Random().nextInt(price+1);
                d=num*0.01;
                BigDecimal d1= new BigDecimal(d);
                String d2= String.valueOf(d1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                x[3]=d2;
            }
        }
        List list = new ArrayList();
        for(int i = 0;i < x.length;i++){
            System.out.print(x[i]+", ");
            list.add(x[i]);
        }
        Collections.shuffle(list);
        return list;
    }

    public static List ticket3() {
        int price = new Random().nextInt(301)+500;
        System.out.println(price);
        double a=0;
        double b=0;
        double c=0;
        double d=0;
        int num=0;
        String[] x=new String[4];
        for (int i=0;i<4;i++){
            if (i==0){
                price=price-num;
                num= new Random().nextInt(price+1);
                a=num*0.01;
                BigDecimal a1= new BigDecimal(a);
                String a2= String.valueOf(a1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                x[0]=a2;
            }
            if (i==1){
                price=price-num;
                num= new Random().nextInt(price+1);
                b=num*0.01;
                BigDecimal b1= new BigDecimal(b);
                String b2= String.valueOf(b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                x[1]=b2;
            }
            if (i==2){
                price=price-num;
                num= new Random().nextInt(price+1);
                c=num*0.01;
                BigDecimal c1= new BigDecimal(c);
                String c2= String.valueOf(c1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                x[2]=c2;
            }
            if (i==3){
                num= new Random().nextInt(price+1);
                d=num*0.01;
                BigDecimal d1= new BigDecimal(d);
                String d2= String.valueOf(d1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                x[3]=d2;
            }
        }
        List list = new ArrayList();
        for(int i = 0;i < x.length;i++){
            System.out.print(x[i]+", ");
            list.add(x[i]);
        }
        Collections.shuffle(list);
        return list;
    }

    public static List ticket4() {
        int price = new Random().nextInt(201)+200;
        System.out.println(price);
        double a=0;
        double b=0;
        double c=0;
        double d=0;
        int num=0;
        String[] x=new String[4];
        for (int i=0;i<4;i++){
            if (i==0){
                price=price-num;
                num= new Random().nextInt(price+1);
                a=num*0.01;
                BigDecimal a1= new BigDecimal(a);
                String a2= String.valueOf(a1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                x[0]=a2;
            }
            if (i==1){
                price=price-num;
                num= new Random().nextInt(price+1);
                b=num*0.01;
                BigDecimal b1= new BigDecimal(b);
                String b2= String.valueOf(b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                x[1]=b2;
            }
            if (i==2){
                price=price-num;
                num= new Random().nextInt(price+1);
                c=num*0.01;
                BigDecimal c1= new BigDecimal(c);
                String c2= String.valueOf(c1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                x[2]=c2;
            }
            if (i==3){
                num= new Random().nextInt(price+1);
                d=num*0.01;
                BigDecimal d1= new BigDecimal(d);
                String d2= String.valueOf(d1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
                x[3]=d2;
            }
        }
        List list = new ArrayList();
        for(int i = 0;i < x.length;i++){
            System.out.print(x[i]+", ");
            list.add(x[i]);
        }
        Collections.shuffle(list);
        return list;
    }

    /**
     * 生成邀请码
     */
    public static String createCode(int userid){
        return "";
    }
    /**
     * 解析邀请码
     */

}